//
//  UILabel+Ext.m
//  Excellence
//
//  Created by 帝云科技 on 2017/6/19.
//  Copyright © 2017年 diyunkeji. All rights reserved.
//

#import "UILabel+Ext.h"
#import <objc/runtime.h>

@implementation UILabel (Ext)

+ (instancetype)xhq_layoutColor:(UIColor *)color
                           font:(UIFont *)font
                           text:(NSString *)text {
    return [self xhq_labelFrame:CGRectZero
                        bgColor:[UIColor clearColor]
                      textColor:color
                  textAlignment:0
                           font:font
                           text:text];
}

+ (instancetype)xhq_labelFrame:(CGRect)frame
                       bgColor:(UIColor *)bgColor
                     textColor:(UIColor *)tColor
                 textAlignment:(NSTextAlignment)alignment
                          font:(UIFont *)font
                          text:(NSString *)text {
    return ({
        UILabel *label = [[UILabel alloc]initWithFrame:frame];
        label.textColor = tColor;
        label.backgroundColor = bgColor;
        label.textAlignment = alignment;
        label.font = font;
        label.text = text;
        label;
    });
}

+ (instancetype)xhq_lineLabel {
    return ({
        UILabel *label = [[UILabel alloc]init];
        label.backgroundColor = [UIColor xhq_line];
        label;
    });
}

+ (instancetype)labelWithTitle:(NSString *)title titleFontSize:(CGFloat )font textColor:(UIColor *)color backgroundColor:(UIColor *)bgColor alignment:(NSTextAlignment)textAlignment{
    return ({
        UILabel *label = [[UILabel alloc] init];
        label.text = title;
        label.font = kFont(font);
        label.textColor = color;
        if (bgColor) {
            label.backgroundColor = bgColor;
        }
        label.textAlignment = textAlignment;
        label;
    });
}

@end

@implementation UILabel (customText)

/*
+ (void)load {
    
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        Class instanceClass = [self class];
        
        SEL originalSelector = @selector(setFont:);
        SEL swizzledSelector = @selector(xhq_setFont:);
        
        Method originalMethod = class_getInstanceMethod(instanceClass, originalSelector);
        Method swizzledMethod = class_getInstanceMethod(instanceClass, swizzledSelector);
        
        BOOL isAddMethod = class_addMethod(instanceClass, originalSelector, method_getImplementation(swizzledMethod), method_getTypeEncoding(swizzledMethod));
        if (isAddMethod) {
            class_replaceMethod(instanceClass, swizzledSelector, method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod));
        }else {
            method_exchangeImplementations(originalMethod, swizzledMethod);
        }
        
    });
}

- (void)xhq_setFont:(UIFont *)font {
    UIFont *aFont = [UIFont fontWithName:@"TrebuchetMS" size:font.pointSize];
    [self xhq_setFont:aFont];
}
*/


@end
